package fractal.model;

/** Class create fractal value */
public class MandelbrotFractal {

	/** method return fractal value */
	public static double value(double x, double y, int rep) {
		double z_re2 = 0;
		double z_im2 = 0;
		double z_re = 0;
		double z_im = 0;
		int i;

		for (i = -1; (i < rep); i++) {
			z_re2 = z_re * z_re;
			z_im2 = z_im * z_im;

			if (z_re2 + z_im2 < 4) {
				z_im = 2 * z_re * z_im + y;
				z_re = z_re2 - z_im2 + x;
			}
			else break;
		}
		return (double) i / (double) rep;
	}
}
